package com.cositas.dulces.lp.action.impl;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cositas.dulces.lp.action.Action;
import com.cositas.dulces.lp.action.BackendAction;
import com.cositas.dulces.lp.model.ShoppingCart;
import com.cositas.dulces.lp.model.ShoppingCartStatus;
import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

// TODO Acciones sobre el carrito de la persona
// TODO marcar un pedido no pending

public class DownloadShoppingCartAction implements Action {

	public void doAction(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		BackendAction.checkUser();
		if (req.getParameter("or").equals("1")) {
			// order request
			Objectify ofy = ObjectifyService.begin();
			Query<ShoppingCart> iter = ofy.query(ShoppingCart.class).filter("status", ShoppingCartStatus.ORDER_REQUEST.name()).filter("pending", Boolean.TRUE);
			for (ShoppingCart sc : iter) {
				resp.getWriter().println(sc);	
			}
		} else {
			// budget request
			Objectify ofy = ObjectifyService.begin();
			Query<ShoppingCart> iter = ofy.query(ShoppingCart.class).filter("status", ShoppingCartStatus.BUDGET_REQUEST.name()).filter("pending", Boolean.TRUE);
			for (ShoppingCart sc : iter) {
				resp.getWriter().println(sc);	
			}
		}
	}
}
